package com.hue.workqueue;

import com.hue.utils.ConnectionUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/*
    工作队列模式：生产者
 */
public class Product {
    public static void main(String[] args) throws IOException, TimeoutException {
        //获取连接
        Connection connection = ConnectionUtils.getConnection();
        //创建频道
        Channel channel = connection.createChannel();
        //创建队列
        channel.queueDeclare("work_queue", true,false,false,null);
        //发送多个消息
        for (int i = 0; i < 30; i++) {
            channel.basicPublish("","work_queue",null,("hello world"+i).getBytes());
        }
        //关闭连接
        channel.close();
        connection.close();
    }
}
